/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-30 17:17:29
 * @LastEditTime: 2019-09-09 14:54:38
 * @LastEditors: Please set LastEditors
 */
export function createStore (reducer){
    // if(enhancer){
    //     return enhancer(createStore)(reducer)
    // }
    // if(typeof reducer != "Function"){
    //     console.error("function createStore arguments is function")
    //     return false;
    // }

    // 定义一个默认的 state
    let store = null;
    // 定义一个监听数组
    let listening = [];
    // 获取state的值
    let initAction = {type:"@init#Dispacth%"}
    function getState(){
        return store;
    }
    function dispatch(action=initAction){
        store = reducer(store,action);

        listening.forEach(element => {
            element();
        });
        // console.log("hjk")
        // return result
        return action;
    }
    function subscribe(fun){
        if(typeof fun === "function"){
            listening.push(fun);
        }else{
            console.error("function subscibe arguments is function");
        }
    }
    // function LastEditTime
    dispatch()
    return {
        getState,
        dispatch,
        subscribe
    }
}


// export function  applyMiddleWare(){
//     return 
// }
